﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows;
using System.Linq;
using OfficeOpenXml;

namespace ToolExcelPub
{
    public static partial class XTool
    {
        public static void ReadPclass()
        {
            ShowInfo("ReadPclass!");

            var DictEnumTemp = new Dictionary<string, Dictionary<string, string>>();

            foreach (var fileinfo in DictXFileInfo.Values)
            {
                if (!fileinfo.HasType(EToolFileType.公共类))
                {
                    continue;
                }
                var PathPclass = fileinfo.FileName;
                if (File.Exists(PathPclass))
                {
                    using (var package = new ExcelPackage(new FileInfo(PathPclass)))
                    {
                        var wk = package.Workbook;
                        foreach (var sheet in wk.Worksheets)
                        {
                            var rows = sheet.Dimension.End.Row;
                            var enumcols = sheet.Dimension.End.Column;

                            for (int i = 3; i <= rows; i++)
                            {
                                var cell1 = sheet.GetValue(i, 1);
                                var cell2 = sheet.GetValue(i, 2);
                                if (cell1 == null || cell2 == null)
                                {
                                    continue;
                                }
                                var node = new XPclassInfo();
                                node.Name = cell1.ToString();
                                node.Desc = cell2.ToString();

                                for (int j = 3; j <= enumcols; j++)
                                {
                                    var cellj = sheet.GetValue(i, j);
                                    if (cellj == null)
                                    {
                                        continue;
                                    }
                                    List<string> list = cellj.ToString().ToListString();
                                    if (list.Count < 2)
                                    {
                                        continue;
                                    }
                                    if (list.Count < 3)
                                    {
                                        list.Add("");
                                    }
                                    node.ListNode.Add(list);
                                }
                                DictXPclassInfo[node.Name] = node;
                            }
                        }
                    }
                    
                }
            }
        }
        public class XPclassInfo
        {
            public string Name = "";
            public string Desc = "";
            public List<List<string>> ListNode = new();//字段列表 <<字段类型, 字段名, 字段注释>>
        }
    }
}
